//$Id:  $
//$Date:  $
//$Author:  $
package com.ajaxit.prisa.struts;

import java.util.Collection;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessages;

import com.ajaxit.prisa.daos.ModuloDAO;
import com.ajaxit.prisa.daos.PaginaDAO;
import com.ajaxit.prisa.values.ModuloVO;
import com.ajaxit.prisa.values.PaginaVO;

public class GenerarSubmenuAction extends Action {
	private static final long serialVersionUID = 1L;

	public ActionForward execute ( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception {
		GenerarSubmenuForm validarUsuarioForm = (GenerarSubmenuForm)form;
        HttpSession session = request.getSession ( );
        long mod = Long.parseLong ( validarUsuarioForm.getModulo ( ) );
        ModuloVO modulo = ModuloDAO.getInstance().findByPrimaryKey ( mod );
        Collection<PaginaVO> paginas = PaginaDAO.getInstance ( ).findByModulo ( mod );
        session.setAttribute ( "modulo", modulo );
        session.setAttribute ( "paginas", paginas );
		return mapping.findForward ( "success" );
	}

	private ActionForward sendError ( ActionMapping mapping, HttpServletRequest request, ActionMessages errors ) {
		saveErrors ( request, errors );
		return new ActionForward ( mapping.getInput ( ) );
	}
}
//$Revision:  $
